import React from "react"

import http from "../../helper/request"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.post<T>(url, body)
		setLoading(false)
		return ret
	}
	const getPaymentMerchant = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchant/list", body)
		return ret
	}

	const paymentMerchantConfigList = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchantConfig/query", body)
		return ret
	}

	const paymentMerchantConfigStartOrStop = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchantConfig/startOrStop", body)
		return ret
	}

	const addPaymentMerchantConfig = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchantConfig/add", body)
		return ret
	}
	const updatePaymentMerchantConfig = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchantConfig/update", body)
		return ret
	}
	const getPayMerchantName = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchant/getPayMerchantName", body)
		return ret
	}

	const paymentMerchantList = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchant/query", body)
		return ret
	}
	const addpaymentMerchant = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchant/add", body)
		return ret
	}
	const updatepaymentMerchant = async (body: object | undefined) => {
		const ret = await generalHttp("/paymentMerchant/update", body)
		return ret
	}
	return {
		paymentMerchantList,
		addpaymentMerchant,
		updatepaymentMerchant,
		getPayMerchantName,
		updatePaymentMerchantConfig,
		getPaymentMerchant,
		paymentMerchantConfigStartOrStop,
		addPaymentMerchantConfig,
		generalHttp,
		paymentMerchantConfigList,
		loading
	}
}

export default useApi
